import wx
import wx.html as html
import os

class IDEObject:
    def __init__(self, name='noname', path=None):
        self.saved = False
        self.path = path
        self.name = name

class Doc(IDEObject):
    def __init__(self, cont='', name='Doc', path=None):
        IDEObject.__init__(self, name, path)
        self.cont = cont
        self.saved = not path is None


class DocPad(html.HtmlWindow):
    def __init__(self, parent, doc = ('', 'Doc', None)):
        html.HtmlWindow.__init__(self, parent, id=wx.ID_ANY, style=wx.NO_FULL_REPAINT_ON_RESIZE)
        if "gtk2" in wx.PlatformInfo or "gtk3" in wx.PlatformInfo:
            self.SetStandardFonts()
        self.set_doc(Doc(*doc))
        self.fixed = False
        
        self.app = self.GetGrandParent().GetParent()

    def OnLinkClicked(self, linkinfo):
        print('OnLinkClicked: %s\n' % linkinfo.GetHref())
        ref = linkinfo.GetHref()
        self.app.on_open(os.path.abspath(ref), False)
    
    def OnClose(self, event):
        return
                  
    def set_doc(self, doc):
        self.doc = doc
        self.SetPage(doc.cont)

    @property
    def object(self): return self.doc

    @object.setter
    def object(self, obj): self.set_doc(obj)
    

    @property
    def name(self):
        return os.path.split(self.code.name)[-1]


if __name__ == '__main__':
    app = wx.App()
    frame = wx.Frame(None)
    pad = DocPad(frame)
    pad.LoadPage('test/readme.html')
    frame.Show()
    app.MainLoop()